import json

from ut.read_config import read_computation_sheet_config, get_read_computation_path
from ut.windows_ui import select_folder, show_warning


#读取保存地址
def get_sheet_address():
    config=read_computation_sheet_config()
    adrr=config.get("config",[{}])[1].get("save_path")
    return adrr
#修改保存地址
def set_sheet_address():
    adrr=select_folder()
    if adrr is None or adrr==" ":
        show_warning("保存地址不能为空！")
        return
    config=read_computation_sheet_config()
    config["config"][1]["save_path"]=adrr
    try:
        with open(get_read_computation_path(),'w',encoding='utf-8') as f:
            json.dump(config,f,ensure_ascii=False,indent=4)
        show_warning("保存地址修改成功！")
    except Exception as e:
        print(e)